import base64
from zhipuai import ZhipuAI

img_url = "https://cdn.bigmodel.cn/activitytemp/27054ffe-64dd-43ea-89b0-547477ebada7.png"

img_path = "C:/Users/shanshi/Desktop/files/miscellaneous/MCP_server/img/buliangren.jpg"
with open(img_path, 'rb') as img_file:
    img_base = base64.b64encode(img_file.read()).decode('utf-8')

client = ZhipuAI(api_key="52238c00e571469dbcfd684b5dd81751.atRQEakrZ1qsJnxm") # 填写您自己的APIKey
response = client.chat.completions.create(
    model="glm-4.1v-thinking-flashx",  # 填写需要调用的模型名称
    messages=[
      {
        "role": "user",
        "content": [
          {
            "type": "image_url",
            "image_url": {
                "url": f"data:image/jpeg;base64,{img_base}"
                # "url": f"{img_url}"
            }
          },
          {
            "type": "text",
            "text": "请描述这个图片"
          }
        ]
      }
    ]
)
print(response.choices[0].message)

# 保存为md文件
with open("MCP_server/md/output.md", "w", encoding="utf-8") as f:
    f.write(str(response.choices[0].message.content))

